package domein.client;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import Gui.MainFrame;
import domein.server.IBuilder;


public class RMIClient extends UnicastRemoteObject implements IClient
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6928596719721653591L;
	private MainFrame gui;
	private IBuilder builder;
	private int ID;
	
	public RMIClient(String ip) throws RemoteException {
		super();
		String name = "Builder";
        Registry registry = LocateRegistry.getRegistry(ip,1099);
       
		try {
			
			builder = (IBuilder) registry.lookup(name);
			
			builder.addObserver(this);
			ID = builder.getID();
			gui = new MainFrame(ID, builder);
			
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
		
	}


	@Override
	public void update() throws RemoteException {
		gui.update(builder,ID);
	}


	@Override
	public int getID()   {
		return ID;
	}

}